package com.example.dormmanage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.dormmanage.entity.Admin;
import com.example.dormmanage.service.impl.AdminService;
import com.example.dormmanage.view.ResultView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/manager")
@Api(tags = "管理员管理")
public class AdminManageController {

    @Autowired
    private AdminService adminService;

    @GetMapping
    @ApiOperation("查询管理员列表")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "page", value = "页码", required = true,dataTypeClass = Integer.class ),
                    @ApiImplicitParam(name = "pageSize", value = "每页数据量", required = true,dataTypeClass = Integer.class),
                    @ApiImplicitParam(name = "name", value = "管理员姓名", required = false,dataTypeClass = String.class)
            }
    )
    public ResultView<Page> selectAdminList(Integer page, Integer pageSize, String name){
        return adminService.selectAdminList(page,pageSize,name);
    }

    @PostMapping()
    @ApiOperation("新增管理员")
    public ResultView<String> addAdmin(@RequestBody Admin admin){
        return adminService.addAdmin(admin);
    }

    @GetMapping("/{adminId}")
    @ApiOperation("查询管理员详细信息")
    public ResultView<Admin> selectAdminDetail(@PathVariable Long adminId){
        return adminService.selectAdminDetail(adminId);
    }

    @GetMapping("/getZones/{adminId}")
    @ApiOperation("查询宿舍管理员管理区域")
    public ResultView<List<String>> selectAdminManageArea(@PathVariable Long adminId){
        return adminService.selectAdminManageArea(adminId);
    }

    @PostMapping("//setZones/{adminId}")
    @ApiOperation("为管理员分配管理楼宇")
    public ResultView<String> AdminSetZones(@PathVariable Long adminId){
        return adminService.AdminSetZones(adminId);
    }
}
